<%-- 
    Document   : searchResults
    Created on : Nov 24, 2011, 1:53:45 PM
    Author     : rkoretke
--%>

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"  pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/WEB-INF/views/includes.jsp" %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Flix Search Results</title>
        <link rel="stylesheet" type="text/css" href="/cheapflix/css/style.css" />
    </head>
    <body>

        <jsp:useBean id="SearchCriteria" scope="session" class="com.cheapflix.beans.SearchCriteria"/>
        <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <div class="outer">
            <%@ include file="/WEB-INF/views/header.jsp" %>
            <div class="row rowstyle rowleft">
                <form action="/cheapflix/search" method="GET">
                    <input type="text" name="searchField" value="${SearchCriteria.basicSearch}"/>
                    <input type="submit" value="Search"><br>
                    <a href="/cheapflix/searchAdvanced">Advanced Search</a>
                    <hr>
                    <c:choose>
                        <c:when test="${SearchCriteria.totalResults == 0}">
                            <span class="message">
                                No matching results found.
                            </span>
                        </c:when>
                        <c:otherwise>
                            <div class="searchResults">
                                <% int i = 0;
                                %>
                                <c:forEach var="dvd" items="${SearchCriteria.dvds}"
                                           begin="${SearchCriteria.startIndex}"
                                           end="${SearchCriteria.endIndex}" varStatus="status">
                                    <%
                                        String cssClass = "";
                                        if (i < SearchCriteria.getEndIndex())
                                        {
                                            cssClass = "SingleResult";
                                        }
                                    %>
                                    <div class="<%= cssClass%>">
                                        <c:out value="${status.index + 1}"/>.
                                        <a href="/cheapflix/searchId?id=${dvd.id}"><c:out value='${dvd.title}'/></a><br>
                                        <span class="srLabel">Genre: </span><c:out value="${dvd.genre}"/><br>
                                        <span class="srLabel">Starring: </span><c:out value="${dvd.actors}"/><br>
                                    </div>

                                    <% i++;%>
                                </c:forEach>
                                <c:choose>
                                    <c:when test="${SearchCriteria.startIndex > 0}">
                                        <input type="submit" name="prev" value="Previous"/>
                                    </c:when>
                                </c:choose>
                                <c:choose>
                                    <c:when test="${SearchCriteria.endIndex < SearchCriteria.totalResults - 1}">
                                        <input type="submit" name="next" value="Next"/>
                                    </c:when>
                                </c:choose>
                            </div>
                            <span class="message" >Showing Results <c:out value="${SearchCriteria.startIndex + 1}"/> to
                                <c:out value="${SearchCriteria.endIndex + 1}"/> of
                                <c:out value="${SearchCriteria.totalResults}"/>
                            </span>
                        </c:otherwise>
                    </c:choose>
                </form>
            </div>
                     <%@ include file="/WEB-INF/views/footer.jsp" %>
        </div>
    </body>
</html>